package com.activity.shop;

import android.os.Bundle;
import android.view.View;

import com.activity.App;
import com.activity.WebActivity;
import com.activity.fragment.DefineQueryFragment;
import com.activity.fragment.DefineSheetQueryFragment;
import com.activity.fragment.MemberFragment;
import com.activity.fragment.MonthRecordFragment;
import com.activity.fragment.MonthSheetFragment;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.activity.home.PageActivity;
import com.example.apple.ddhr_new.activity.setting.WebViewActivity;
import com.example.apple.ddhr_new.utils.ActivityUtil;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import static com.example.apple.ddhr_new.activity.setting.WebViewActivity.INTENT_TITLE;
import static com.example.apple.ddhr_new.activity.setting.WebViewActivity.INTENT_URL;
import static com.example.http.HttpClient.BASE_URL;

public class SheetActivity extends PageActivity {

    private String[] mTitleDataList;
    private ArrayList<Fragment> fragments =new ArrayList();
    private int type;

    @Override
    public String[] titles() {
        if(mTitleDataList==null){
            mTitleDataList = new String[]{"日期报表","人员报表"};
        }

        return mTitleDataList;
    }

    @Override
    public ArrayList<Fragment> fragments() {

        if(fragments.size()==0){

            MonthSheetFragment  monthSheetFragment= new MonthSheetFragment();
            monthSheetFragment.type = type;
            MemberFragment memberFragment =new MemberFragment();
            memberFragment.type = type;
            fragments.add(monthSheetFragment);
            fragments.add(memberFragment);
        }

        return  fragments;
    }

    @Override
    protected int titleText() {
        return R.string.kaoqin_baobiao;
    }

    @Override
    protected void created(@Nullable Bundle savedInstanceState) {


        setImageRight(R.drawable.rili);
        type =getIntent().getExtras().getInt("type");
        if(type==1){
            setTitleText("外出报表");
        }else if (type==2){
            setTitleText("加班报表");
        }
        super.created(savedInstanceState);

    }

    @Override
    protected void titleRightClick() {


        if(type==1){
                    Bundle param = new Bundle();
        param.putString(INTENT_TITLE,"外出报表");

        String url = "http://106.15.46.6:8086/outreport?storeno="+ App.getInstance().userstoreinfoBean.getStoreno();

        param.putString(INTENT_URL,url);
        ActivityUtil.startActivity(this, WebActivity.class,param);

        return;
        }
        if(type==2){
            Bundle param = new Bundle();
            param.putString(INTENT_TITLE,"加班报表");

            String url = "http://106.15.46.6:8086/otreport?storeno"+ App.getInstance().userstoreinfoBean.getStoreno();

            param.putString(INTENT_URL,url);
            ActivityUtil.startActivity(this, WebActivity.class,param);

            return;
        }
        Bundle param = new Bundle();
        param.putString(INTENT_TITLE,getString(R.string.kaoqin_baobiao));

        String url = "http://106.15.46.6:8086/checkinreport?storeno="+ App.getInstance().userstoreinfoBean.getStoreno();
        MonthSheetFragment fragment = (MonthSheetFragment) fragments.get(0);

        if(StringUtils.isNotEmpty( fragment.monthAdapter.beginTime))
        {
            url=url+"&date1="+fragment.monthAdapter.beginTime;
            param.putString("begin",fragment.monthAdapter.beginTime);
        }
        if(StringUtils.isNotEmpty( fragment.monthAdapter.endTime))
        {
            url=url+"&date2="+fragment.monthAdapter.endTime;
            param.putString("end",fragment.monthAdapter.endTime);
        }

//
        param.putString(INTENT_URL,url);
        ActivityUtil.startActivity(this,WebActivity.class,param);


    }

    @Override
    public void positionSelected(int position) {
        if(position==0){
            buttonRight.setVisibility(View.VISIBLE);
        }else {
            buttonRight.setVisibility(View.GONE);
        }
    }
}
